// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'

import App from './App'
import router from './router'
import store from './store'
import iView from 'iview'
import 'iview/dist/styles/iview.css'
import axios from 'axios'

Vue.config.productionTip = false
Vue.prototype.$http = axios
axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest'
axios.defaults.headers.get['X-Requested-With'] = 'XMLHttpRequest'

axios.defaults.withCredentials = true
Vue.use(iView)
/* Vue.use(N3Components) */
axios.interceptors.response.use((response) => {
  if (response.data.code === 401) {
    store.dispatch('destroyUser')
    router.replace({ path: '/login' })
    return response
  } else {
    return response
  }
}, (response) => {
  //
  store.dispatch('destroyUser')
  router.replace({ path: '/login' })
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
